import React, {Fragment} from 'react';
import {Button, Card} from 'antd';
import Result from '../../components/Result';
import {connect} from 'dva';
import PageHeaderLayout from 'components/Layout/PageHeaderLayout';
import {Link} from 'react-router';

const successPage = ({location, dispatch, success, loading}) => {

  const {areaText, listUrl, detailUrl} = success;

  /**
   * 返回列表
   * @param {列表url} listUrl
   */
  const backToList = (listUrl) => {
    dispatch({
      type: 'success/backToList',
      payload: {
        listUrl: listUrl
      }
    });
  };

  /**
   * 查看详情
   * @param {详情url} detailUrl
   */
  const backToDetail = (detailUrl) => {
    dispatch({
      type: 'success/backToDetail',
      payload: {
        detailUrl: detailUrl
      }
    });
  };

  const actions = (
    <Fragment>
      <Button type="primary" onClick={() => backToList(listUrl)}>
        返回列表
      </Button>
      <Button onClick={() => backToDetail(detailUrl)}>查看详情</Button>
    </Fragment>
  );
  return (
    <PageHeaderLayout>
      <Card bordered={false}>
        <Result
          type="success"
          title="提交成功"
          description={areaText}
          actions={actions}
          style={{
          marginTop: 48,
          marginBottom: 16
        }}/>
      </Card>
    </PageHeaderLayout>
  )
}

export default connect(({success, loading}) => ({success, loading}))(successPage)
